// electronAPI.js
const { ipcRenderer } = require('electron');

// 暴露安全的API给渲染进程
const electronAPI = {
  // 获取Ollama模型列表
  getModels: () => ipcRenderer.invoke('get-models'),
  
  // 更新设置
  updateSettings: (settings) => ipcRenderer.invoke('update-settings', settings),
  
  // 获取当前设置
  getSettings: () => ipcRenderer.invoke('get-settings'),
  
  // 监听设置更新
  onSettingsUpdated: (callback) => ipcRenderer.on('settings-updated', callback),
  
  
  // 发送消息
  sendMessage: (message) => ipcRenderer.send('send-message', message),
  
  // 检查Ollama状态
  checkOllamaStatus: () => ipcRenderer.send('check-ollama-status'),
  
  // 监听AI处理状态
  onAiProcessing: (callback) => ipcRenderer.on('ai-processing', callback),
  
  // 监听AI思考过程
  onAiThinking: (callback) => ipcRenderer.on('ai-thinking', callback),
  
  // 监听AI思考流
  onAiThinkingStream: (callback) => ipcRenderer.on('ai-thinking-stream', callback),
  
  // 监听AI流式响应
  onAiStreamResponse: (callback) => ipcRenderer.on('ai-stream-response', callback),
  
  // 监听AI响应
  onAiResponse: (callback) => ipcRenderer.on('ai-response', callback),
    // 监听Ollama状态
  onOllamaStatus: (callback) => ipcRenderer.on('ollama-status', callback),

  // 设置用户ID
  setUserId: (userId) => ipcRenderer.send('set-user-id', userId),
  
  // 获取用户ID
  getUserId: () => ipcRenderer.invoke('get-user-id'),
};

module.exports = electronAPI;
